<?php

/**
 * Libros
 *  
 * @author Administrador
 * @version 
 */

require_once 'Zend/Db/Table/Abstract.php';

class Model_DBTable_Libros extends Zend_Db_Table_Abstract {
	/**
	 * The default table name 
	 */
	protected $_name = 'libros';
	
	public function getLibro($id)
	{
		$id = (int)$id;
		$row = $this->fetchRow('id = ' . $id);
		if (!$row)
		{
			throw new Exception("Count not find row $id");
		}
		return $row->toArray();
	}
	
	public function addLibro($titulo, $autor){
		$data = array('titulo' => $titulo, 'autor' => $autor,);
		$this->insert($data);
	}
	
	public function updateLibro($id, $titulo, $autor){
		$data = array('titulo' => $titulo, 'autor' => $autor,);
		$this->update($data, 'id = '. (int)$id);
	}
	
	public function deleteLibro($id){
		$this->delete('id =' . (int)$id);
	}  
  
    public function getAll()
    {
      //SELECT * FROM camdev.articulos a inner join categorias c on a.id_categoria = c.id_categoria 
        $query= $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
                        //->from(array('a' => 'articulos'), array())
                        ->join('categorias', 'articulos.id_categoria = categorias.id_categoria')
                        ->order('fecha DESC')
                
                //->group('articulos.id_articulo')
                
                ;
         $query->setIntegrityCheck(false);               //->limit(5);
        //debug($sql->_toString());
         $sql = "SELECT * FROM camdev.articulos a inner join categorias c on a.id_categoria = c.id_categoria ";
         //$this->s
        return $this->fetchAll($query);

      
    } 
}